package com.twentyOne.ClothingLand.service.impl;

import java.util.List;

import com.twentyOne.ClothingLand.dao.IGoodsDAO;
import com.twentyOne.ClothingLand.dao.impl.GoodsDAO;
import com.twentyOne.ClothingLand.service.IGoodsService;
import com.twentyOne.ClothingLand.vo.Goods;

public class GoodsService implements IGoodsService {
	
	private IGoodsDAO goodsDAO = new GoodsDAO();
	
	@Override
	public void addGoods(Goods goods) {
		goods.setGoodsId(0);
		String ID = this.goodsDAO.addGoods(goods) + "";
		int len = ID.length();
		for (int i = 0; i < (6-len); i++) {
			if (i == (5-len)) {
				ID = "4" + ID;
			}else {
				ID = "0" + ID;
			}
		}
		int goodsId = Integer.parseInt(ID);
		goods.setGoodsId(goodsId);
		this.goodsDAO.modifyGoods(goods);
		
	}

	@Override
	public void deleteGoods(Goods goods) {
		
		this.goodsDAO.deleteGoods(goods);
		
	}

	@Override
	public void modifyGoods(Goods goods) {
		
		goods.setId(this.searchGoodsByID(goods.getGoodsId()).getId());
		this.goodsDAO.modifyGoods(goods);
		
	}

	@Override
	public List<Goods> searchAllGoods() {
		
		return this.goodsDAO.searchAllGoods();
		
	}

	@Override
	public Goods searchGoodsByID(int goodsId) {

		return this.goodsDAO.searchGoodsByID(goodsId);
		
	}

	@Override
	public List<Goods> searchGoodsByName(String name) {

		return this.goodsDAO.searchGoodsByName(name);
		
	}

	@Override
	public List<Goods> searchGoodsByPrice(Double minPrice, Double maxPrice) {

		return this.goodsDAO.searchGoodsByPrice(minPrice, maxPrice);
		
	}

	@Override
	public List<Goods> searchGoodsByClassId(String classId) {
		
		return this.goodsDAO.searchGoodsByClassId(classId);
		
	}

	@Override
	public List<Goods> searchGoodsByBrandId(int brandId) {
		
		return this.goodsDAO.searchGoodsByBrandId(brandId);
		
	}

}
